﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using GdHotel.Web.Controllers;
using GdHotel.Web.Models;
using UniqueTechnologies.Attributes;

namespace GdHotel.Web.Attributes
{
    public class LayoutSupportAttribute : LanguageSupportAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            var controller = (BaseUiController)filterContext.Controller;

            var language = controller.Language;
            var note = controller.NotesRepository.FindAllByLang(language).FirstOrDefault();
            var mainMenuItems = controller.MainMenuItemsRepository.FindAllByLang(language).OrderBy(i => i.Order);
            var additionalMenuItems = controller.AdditionalMenuItemsRepository.FindAllByLang(language).OrderBy(i => i.Order);
            var uiModel = new UiModel { Note = note, Language = language, MainMenuItems = mainMenuItems, AdditionalMenuItems = additionalMenuItems};

            controller.ViewData["LayoutModel"] = uiModel;
        }
    }
}